package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.makeramen.roundedimageview.RoundedImageView;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.FindPackersEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
*@author 陈方凯
*@date 2020/6/15
*description:
*/
public class FindPackersAdapter2 extends BaseRecycleAdapter<FindPackersEntity> {

    private RequestManager requestManager;
    private boolean isClass;

    public FindPackersAdapter2(Context context, List<FindPackersEntity> data, RequestManager requestManager) {
        super(context, R.layout.item_find_packers2, data);
        this.requestManager = requestManager;
    }


    @Override
    public void convert(ItemViewHolder holder, final FindPackersEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tvPackersTitle = holder.itemView.findViewById(R.id.tv_packers_title);
        RoundedImageView ivPackerAvatar = holder.itemView.findViewById(R.id.iv_packer_avatar);
        LinearLayout lvTeamPerson = holder.itemView.findViewById(R.id.lv_team_person);
        TextView tvTime = holder.itemView.findViewById(R.id.tv_time);
        if (null != entity.getAvatarAddress() && !TextUtils.isEmpty(entity.getAvatarAddress())) {
            RequestOptions options = new RequestOptions()
                    .placeholder(entity.getTeamType() == 0 ? R.mipmap.construction_team_detail: R.mipmap.professional_crew_detail)
                    .transforms(new CenterCrop(), new RoundedCorners(8));
            requestManager.load(entity.getAvatarAddress()).apply(options).into(ivPackerAvatar);
        } else {
            requestManager.load(entity.getTeamType() == 0 ? R.mipmap.construction_team_detail: R.mipmap.professional_crew_detail).into(ivPackerAvatar);
        }

        if (TextUtils.isEmpty(entity.getTeamNumber()) || "0".equals(entity.getTeamNumber()) || "0人".equals(entity.getTeamNumber())) {
            lvTeamPerson.setVisibility(View.GONE);
        } else {
            lvTeamPerson.setVisibility(View.VISIBLE);
        }
        String[] strArray = entity.getCategory().trim().replaceAll(",","\\|").split("\\|");
        tvTime.setText(String.format("%s 发布", DateUtils.timestampToDate(entity.getCreateTime())));
        tvPackersTitle.setText(String.format("%s-%s-%s",entity.getContact(), strArray[strArray.length - 1] , entity.getTeamType() == 0?"施工队":entity.getTeamType()==1?"班组工队":"承包商"));
    }

}
